
package com.yesep.learn.mqtt.client.handler.protocol;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.yesep.learn.mqtt.client.common.util.FixHeaderUtil;

import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.mqtt.MqttFixedHeader;
import io.netty.handler.codec.mqtt.MqttMessage;
import io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader;
import io.netty.handler.codec.mqtt.MqttMessageType;
import io.netty.handler.codec.mqtt.MqttPubAckMessage;

/**
   * 消息编号：6
 * @Description: PUBREL连接处理，发布释放，保证传递2
 */
public class PubRel {

	private static final Logger logger = LoggerFactory.getLogger(PubRel.class);

	public void process(ChannelHandlerContext ctx, MqttMessage message) {
		MqttFixedHeader fixedHeader = FixHeaderUtil.from(MqttMessageType.PUBCOMP);
		MqttPubAckMessage pubComp = new MqttPubAckMessage(fixedHeader, (MqttMessageIdVariableHeader) message.variableHeader());
		ctx.channel().writeAndFlush(pubComp);
	}

}
